// lib/utils/color.dart
import 'package:flutter/material.dart';

class AppColors {
  // 基础颜色常量
  static final Color color000 = hexToColor('000000');
  static final Color color333 = hexToColor('333333');
  static final Color color666 = hexToColor('#666666');
  static final Color color999 = hexToColor('#999999');
  static final Color colorEEE = hexToColor('#EEEEEE');
  static final Color colorFFF = hexToColor('#FFFFFF');
  static final Color color9C9C9C = hexToColor('#9C9C9C');
  static final Color color6184DD = hexToColor('#6184DD');
  static final Color color007BFF = hexToColor('#007BFF');
  static final Color colorA0A0A9 = hexToColor('#A0A0A9');
  static final Color colorF7F7F7 = hexToColor('#F7F7F7');
  static final Color colorD8D8D8 = hexToColor('#D8D8D8');
  static const Color backgroundGray = Color(0xFFF5F5F5);

  // 主题颜色
  static const Color primaryColor = Color(0xFF333333);
  static const Color secondaryColor = Color(0xFF666666);
  static const Color accentColor = Color(0xFF007AFF);

  // 文本颜色
  static const Color textPrimary = Color(0xFF333333);
  static const Color textSecondary = Color(0xFF666666);
  static const Color textHint = Color(0xFF999999);

  // 背景颜色
  static const Color background = Color(0xFFFFFFFF);
  static const Color backgroundSecondary = Color(0xFFF5F5F5);

  // 边框颜色
  static const Color border = Color(0xFFEEEEEE);

  /// 将十六进制颜色字符串转换为Color对象
  ///
  /// [hexColor] 十六进制颜色字符串，例如 "#333333" 或 "333333"
  /// [alpha] 透明度，取值范围 0-255，默认为 255（不透明）
  ///
  /// 使用示例：
  /// ```dart
  /// Color color1 = AppColors.hexToColor("#333333");
  /// Color color2 = AppColors.hexToColor("333333");
  /// Color color3 = AppColors.hexToColor("#333333", 128); // 50% 透明度
  /// ```
  static Color hexToColor(String hexColor, {int alpha = 255}) {
    // 移除 # 符号（如果存在）
    final hexCode = hexColor.replaceAll('#', '');

    // 验证十六进制颜色代码格式
    if (hexCode.length != 6) {
      throw Exception('Invalid hex color code: $hexColor');
    }

    // 解析RGB值
    final r = int.parse(hexCode.substring(0, 2), radix: 16);
    final g = int.parse(hexCode.substring(2, 4), radix: 16);
    final b = int.parse(hexCode.substring(4, 6), radix: 16);

    // 返回Color对象
    return Color.fromARGB(alpha, r, g, b);
  }

  /// 快捷方法：直接从十六进制字符串创建Color对象
  ///
  /// [hexColor] 十六进制颜色字符串，例如 "#333333"
  ///
  /// 使用示例：
  /// ```dart
  /// Color color = AppColors.fromHex("#333333");
  /// ```
  static Color fromHex(String hexColor) {
    return hexToColor(hexColor);
  }
}
